<template>
    <el-row class="user-info-form" type="flex" justify="center">
        <el-col>
            <el-form label-position="top" :model="editForm" :rules="editFormRules" ref="editForm" @submit.native.prevent>
                <input type="hidden"  v-model="editForm.id">
                <el-form-item label="开始时间：" prop="datetime">
                    <el-date-picker
                      v-model="editForm.datetime"
                      type="datetime"
                      placeholder="选择日期时间"
                      align="right"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      :picker-options="util.intDatePickerOptions()">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label-width="0" class="verifyidentity-button">
                    <el-button @click="closeDialog()">取消</el-button>
                    <el-button type="primary" @click="saveEdit('editForm')">确定</el-button>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
</template>
<script>

import util from '@/utils/util'
import { selectLog} from '@/api/dcx'

export default {
    mame: 'PlatTransDeviceLogForm_list',
    props: {
        editInfo: {
            type: Object,
            required: false
        },
        closeDialog: {
            type: Function,
            required: true
        },
    },
    data() {
        return {
            util:util,
            editForm: {
                datetime: '',
                serverId:'',
            },
            editFormRules: {
                datetime: [
                    { required: true, message: '请选择时间', trigger: 'change' },
                ],
            },
        }
    },
    created() {
        let infoObj = this.editInfo
        if(infoObj.id) {//编辑
          this.editForm.serverId = infoObj.serverId
        }
    },
    methods: {
        saveEdit(formName) {
            // 阻止事件冒泡
            event.stopPropagation()
            let that = this
            that.$refs[formName].validate((valid) => {
                if (valid) {
                    let parames = that.editForm
                    selectLog(parames).then(res => {
                        that.closeDialog(true)
                        if( res.data){
                            window.location.href = res.data
                            that.$message({
                                type: 'success',
                                message: '操作成功!'
                            })
                        }else{
                            that.$message.error('暂无日志')
                        }
                    });
                } else {
                    return false
                }
            });
        },
    }
}
</script>
